// subpackage/pages/relief/list.js
import requestUtil from '../../../baseRequest'
import requestUrls from '../../../requestUrl'
import commonUtils from '../../../utils/util.js'
let openid = wx.getStorageSync('openid')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList:[],
    pagination: {
      pageSize: 5,
      pageNum: 1,
      total: 0
    },

  },
  showDetail(event){
    let orderId = event.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '/subpackage/pages/relief/detail?orderId='+orderId,
    })
  },
  getRescueApplyOrderList(){
    const formData = {
      openId:openid,
      criteria:{
      },
      pageDto:{
        ...this.data.pagination
      }
    };
    requestUtil.postRequest(requestUrls.rescueApply.getPage, formData, (res) => {
      const dataList = res.list;
      if (!res.hasError) {
          let orderList = [];
          for (let i = 0; i < dataList.length; i++) {
            orderList.push({
              ...dataList[i],
              applyDate: commonUtils.formatDate(dataList[i].applyDate, 'yyyy-MM-dd'),
            })
          }
          this.setData({
            orderList : this.data.orderList.concat(orderList),
            pagination:{
              ...this.data.pagination,
              total:res.total
            }
          })
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRescueApplyOrderList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})